{extend name="normal_base" /}
{block name="body"}
    <div class="x-body">

      <!--<blockquote class="layui-elem-quote"></blockquote>-->
      <xblock>
        <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
        <button class="layui-btn" onclick="x_admin_show('添加业务类型','{:url(\'add\')}', 600, 600)"><i class="layui-icon"></i>添加</button>
        <span class="x-right" style="line-height:40px">共有分类数据：{:count($type_list)} 条</span>
      </xblock>
      <table class="layui-table layui-form">
        <thead>
          <tr>
            <th width="20">
              <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
            </th>
            <th>栏目名</th>
            <th width="220">操作</th>
        </thead>
        <tbody class="x-cate">
        {foreach name="type_list" item="vo"}
          <tr cate-id='{$vo["id"]}' fid='{$vo["parent_id"]}' >
            <td>
              <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='{$vo.id}'><i class="layui-icon">&#xe605;</i></div>
            </td>
            <td>
              {if condition="$vo['parent_id'] == 0"}<i class="layui-icon x-show" status='true'>&#xe623;</i>{else /}{:str_repeat('&nbsp;', 12)}{/if}
              {$vo['type']}
            </td>
            <td class="td-manage">
              <a title="编辑" onclick="x_admin_show('编辑','edit/id/{$vo[\'id\']}')" href="javascript:;">
                <i class="layui-icon">&#xe642;</i>&nbsp;
              </a>
              <a title="删除" onclick="type_del(this,{$vo['id']})" href="javascript:;">
                <i class="layui-icon">&#xe640;</i>&nbsp;
              </a>
              {if condition="$vo['parent_id'] == 0"}
                <a title="添加子类型" onclick="x_admin_show('添加子类型','add/pid/{$vo[\'id\']}', 600, 600)" href="javascript:;">
                  <i class="layui-icon">&#xe61f;</i>&nbsp;
                </a>
              {/if}
            </td>
          </tr>
          {/foreach}
        </tbody>
      </table>
    </div>
{/block}

{block name="script"}
<script>
  layui.use('laydate', function(){
    var laydate = layui.laydate;

    //执行一个laydate实例
    laydate.render({
      elem: '#start' //指定元素
    });

    //执行一个laydate实例
    laydate.render({
      elem: '#end' //指定元素
    });
  });

  /*删除*/
  function type_del(obj,id){
    layer.confirm('确认要删除吗？',function(index){
      //发异步删除数据
      $.ajax({
        type: "post",
        url: "delete?id="+id,
        dataType: "json",
        success: function(data){
          if (data.code == 1) {
            layer.msg(data.msg);
          } else {
            layer.msg('已删除!',{icon:1,time:1000});
            $(obj).parents("tr").remove();
          }
        }, error: function(){
          layer.msg("请求出错");
        }
      });
    });
  }

  /**
   * 批量删除
   */
  function delAll () {
    //获取选中的id
    var data = tableCheck.getData();
    if (data.length > 0) {
      layer.confirm('确认要删除吗？',function(index){
        var success = 0;
        //捉到所有被选中的，发异步进行删除
        $.ajax({
          type: "post",
          url: "deleteAll?ids="+data.join(','),
          dataType: "json",
          success: function(data){
            if (data.code == 1) {
              layer.msg(data.msg,{icon:5,time:1500});
            } else {
              layer.msg('已删除!',{icon:1,time:1000});
              success = 1
            }
          }, error: function(){
            layer.msg("请求出错",{icon:5,time:1000});
          }
        });

        setTimeout(function () {
          location.replace(location.href);
        }, 1500);
      });
    }
  }
</script>
{/block}